<template>
  <div>
    <div class="articleList">
      <div
        v-for="article in articleList"
        :key="article.id"
        class="article"
        @click="goArticleDetail(article.id)"
      >
        <img
          v-if="article.coverImg"
          class="article-img"
          :src="article.coverImg"
        >
        <div class="center">
          <div class="title">{{ article.title }}</div>
          <div class="summary">{{ article.summary }}</div>
          <div class="time">{{ article.startTime }}</div>
        </div>
        <div class="source">[{{ article.source }}]</div>
      </div>
      <el-pagination
        class="pagination"
        background
        prev-text="上一页"
        next-text="下一页"
        layout="prev, pager, next,total"
        :total="total"
        :page-size="pageSize"
        :page-num="pageNum"
        @current-change="pageChange"
      />
    </div>
  </div>
</template>

<script>
import { getArticlePage } from '@/api/article/article'
export default {
  data() {
    return {
      articleList: [],
      total: 0,
      pageNum: 1,
      pageSize: 5
    }
  },
  mounted() {
    this.load()
  },
  methods: {
    async load() {
      const categoryId = this.$route.query.categoryId
      const data = await getArticlePage({
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        categoryId: categoryId
      })
      this.articleList = data.data.records
      this.total = data.data.total
    },
    goArticleDetail(id) {
      this.$router.push(`bigdata-articleDetail?id=${id}`)
    },
    pageChange(page) {
      this.pageNum = page
      this.load()
    }
  }
}
</script>
<style lang="scss" scoped>
.articleList{
  width:87%;
  margin:0 auto;
}
.article{
  width: 100%;
  border-bottom: 1px solid #999999;
  padding: 10px;
  height: 190px;
  cursor: pointer;

  .article-img{
    margin-right: 20px;
    width:220px;
    height: 160px;
    object-fit: cover;
    float: left;
  }

  .center{
    float:left;
    width: 50%
  }

  .title{
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 10px;
    word-break: break-all;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
  }

  .title:hover{
    color: #00a651;
  }

  .summary{
    height: 112px;
    color:#999999;
    margin-right: 20px;
    word-break: break-all;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
  }

  .time{
    color:#999999;
  }

  .source{
    float: right;
  }

}

.pagination{
  margin:20px;
}
</style>
